/*******************************************************************************
 * Copyright (c) 2025-08-06 @author <a href="mailto:iffiff1@gmail.com">Tyler Chen</a>.
 * All rights reserved.
 *
 * Contributors:
 *     <a href="mailto:iffiff1@gmail.com">Tyler Chen</a> - initial API and implementation.
 ******************************************************************************/
package org.iff.util.llm.qwen;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;

/**
 * TextMessage
 * <pre>
 * {
 *     "model": "qwen-plus",
 *     "messages": [
 *         {
 *             "role": "system",
 *             "content": "You are a helpful assistant."
 *         },
 *         {
 *             "role": "user",
 *             "content": "你是谁？"
 *         }
 *     ]
 * }
 * </pre>
 * @author <a href="mailto:iffiff1@gmail.com">Tyler Chen</a>
 * @since 2025-08-06
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class TextMessage {
    public static final String ROLE_USER = "user";
    public static final String ROLE_SYSTEM = "system";

    @JsonProperty("model")
    private String model;
    @JsonProperty("messages")
    private List<Messages> messages;
    @JsonProperty("stream")
    private boolean stream;
    @JsonProperty("enable_search")
    private boolean enableSearch;
    @JsonProperty("enable_thinking")
    private boolean enableThinking;

    public static TextMessage of() {
        return new TextMessage();
    }

    public TextMessage model(String model) {
        this.model = model;
        return this;
    }

    public TextMessage stream(boolean stream) {
        this.stream = stream;
        return this;
    }

    public TextMessage enableSearch(boolean enableSearch) {
        this.enableSearch = enableSearch;
        return this;
    }

    public TextMessage enableThinking(boolean enableThinking) {
        this.enableThinking = enableThinking;
        return this;
    }

    public TextMessage message(String role, String content) {
        if(this.messages == null) {
            this.messages = new ArrayList<>();
        }
        this.messages.add(Messages.builder().role(role).content(content).build());
        return this;
    }

    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @JsonIgnoreProperties(ignoreUnknown = true)
    public static class Messages {
        @JsonProperty("role")
        private String role;
        @JsonProperty("content")
        private String content;
    }
}
